<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<style type="text/css">
#gameListT td {
	border:1px solid #bbbbbb;
}
</style>

<script type="text/javascript">
	$(function() {
		$("input[name=datepick1]").datepicker();
		$("input[name=datepick2]").datepicker();
	});
	
	function clearText( textBox ) {
		textBox.value = "";
	}
	function nameInputCtr( sel ) {
		if ( sel.value == "" ) {
			$("input[name=name]").attr("readonly", false);
		} else {
			$("input[name=name]").val("");
			$("input[name=name]").attr("readonly", true);
		}
	}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>

<body>

<h2>게임 등록 현황</h2>
<table width="100%">
    <tr>
        <td>■ 누적 등록 게임 수 : ${pageClass.count } 개</td>
        <td align="right"><input type="button" value="게임 등록" class="bigBtn" onclick="location.href='regGamesForm.ga'"/></td>
    </tr>
</table>
<p/>

<!-- 검색 폼 -->
<form action="searchGames.ga" method="post">
<table width="100%" bgcolor="#eeeeee">
    <tr>
        <td>날짜 선택</td>
        <td>
            Start 
            <input type="text" size="12" maxlength="10" name="datepick1" onclick="clearText(this)" style="cursor:pointer;" readonly/> ~ End 
            <input type="text" size="12" maxlength="10" name="datepick2" onclick="clearText(this)" style="cursor:pointer;" readonly/>
        </td>
        <td>
            상태 
            <select name="status">
                <option value="">전체</option>
                <option value="idle">대기</option>
                <option value="start">서비스</option>
                <option value="stop">정지</option>
            </select>
        </td>
        <td>
            게임 
            <select name="no" onchange="nameInputCtr(this)">
                <option value="">직접 입력</option>
                <c:forEach var="allList" items="${allList }">
                    <option value="${allList.no }">${allList.name }</option>
                </c:forEach>
            </select>
        </td>
        <td>
            게임명 <input name="name" type="text" size="24" maxlength="20"/>
            <input type="submit" value="검색"/>
        </td>
    </tr>
</table>
</form>

<p/>

<!-- 등록된 게임 리스트 -->
    <table id="gameListT" align="center" width="100%" cellpadding="0" cellspacing="0">
        <tr align="center" height="35" class="table_title">
            <td rowspan="2">No.</td>
            <td rowspan="2">등록날짜</td>
            <td rowspan="2">게임명</td>
            <td colspan="2">꽁 게임</td>
            <td colspan="2">꽁돈 게임</td>
            <td colspan="2">타임 게임</td>
            <td colspan="2">스페셜 게임</td>
            <td rowspan="2">상태</td>
            <td rowspan="2">관리</td>
            <td rowspan="2">비고</td>
        </tr>
        <tr align="center" class="table_title">
            <td>PV</td>
            <td>등록수</td>
            <td>PV</td>
            <td>등록수</td>
            <td>PV</td>
            <td>등록수</td>
            <td>PV</td>
            <td>등록수</td>
        </tr>
        <c:forEach var="list" items="${pageClass.pageList }">
        <tr height="25" align="center">
            <td width="5%">${list.no }</td>
            <td width="8%"><fmt:formatDate value="${list.regdate }" pattern="yy-MM-dd"/></td>
            <td>
                <a style="color:#4444ee;" onclick="window.open('./detailGames.ga?no=${list.no}', 'detail', 'scrollbars=yes,status=no,resizable=no,width=1000,height=800')">
                    ${list.name }
                </a>
            </td>
            <td width="5%"></td>
            <td width="5%">${list.ggong_count }</td>
            <td width="5%"></td>
            <td width="5%"></td>
            <td width="5%"></td>
            <td width="5%">${list.time_count }</td>
            <td width="5%"></td>
            <td width="5%">${list.special_count }</td>
            <td width="8%">
                <c:if test="${list.status == 'idle' }">대기</c:if>
                <c:if test="${list.status == 'start' }"><font color="#4444ee">서비스</font></c:if>
                <c:if test="${list.status == 'stop' }"><font color="#ee4444">정지</font></c:if>
            </td>
            <td width="12%">
                <c:if test="${list.status == 'idle' }">
                    <input type="button" value="시작" onclick="javascript:location.href='${pageContext.request.contextPath}/updateGamesStatus.ga?status=start&no=${list.no }'"/>
                    <input type="button" value="정지" onclick="javascript:location.href='${pageContext.request.contextPath}/updateGamesStatus.ga?status=stop&no=${list.no }'"/>
                </c:if>
                <c:if test="${list.status == 'start' }">
                    <input type="button" value="시작" disabled/>
                    <input type="button" value="정지" onclick="javascript:location.href='${pageContext.request.contextPath}/updateGamesStatus.ga?status=stop&no=${list.no }'"/>
                </c:if>
                <c:if test="${list.status == 'stop' }">
                    <input type="button" value="시작" onclick="javascript:location.href='${pageContext.request.contextPath}/updateGamesStatus.ga?status=start&no=${list.no }'"/>
                    <input type="button" value="정지" disabled/>
                </c:if>
            </td>
            <td width="8%">
                    <input type="button" value="입력" onclick="window.open('./gamesMemoPopup.ga?id=${list.no}&memotype=games', 'memo', 'scrollbars=yes,status=no,resizable=no,width=440,height=400')"/>
            </td>
        </tr>
        </c:forEach>
    </table>
    
    <br/>
    
    <!-- 페이징 -->
    <div id="page">
    <c:if test="${pageClass.count > 0 }">
        <c:set var="pageCount" value="${pageClass.count / pageClass.pageSize + ( pageClass.count % pageClass.pageSize == 0 ? 0 : 1 ) }"/>
        <c:set var="startPage" value="${pageClass.pageGroupSize * ( pageClass.numPageGroup - 1 ) + 1 }"/>
        <c:set var="endPage" value="${startPage + pageClass.pageGroupSize - 1 }"/>
        
        <c:if test="${endPage > pageCount }">
            <c:set var="endPage" value="${pageCount }"/>
        </c:if>
        
        <c:if test="${pageClass.numPageGroup > 1 }">
            <c:if test="${pageClass.pageName == 'gamesList' }">
                <a href="./${pageClass.pageName }.ga?pageNum=${ ( pageClass.numPageGroup - 2 ) * pageClass.pageGroupSize + 1 }">[이전]</a>
            </c:if>
            <c:if test="${pageClass.pageName == 'searchGames' }">
                <a href="./${pageClass.pageName }.ga?pageNum=${ ( pageClass.numPageGroup - 2 ) * pageClass.pageGroupSize + 1 }&datepick1=${datepick1}&datepick2=${datepick2}&status=${status}&no=${no}&name=${name}">[이전]</a>
            </c:if>
        </c:if>

        <c:forEach var="i" begin="${startPage }" end="${endPage }">
            <c:if test="${pageClass.currentPage != i }">
                <c:if test="${pageClass.pageName == 'gamesList' }">
                    <a href="./${pageClass.pageName }.ga?pageNum=${i }"> [ ${i } ] </a>
                </c:if>
                <c:if test="${pageClass.pageName == 'searchGames' }">
                    <a href="./${pageClass.pageName }.ga?pageNum=${i }&datepick1=${datepick1}&datepick2=${datepick2}&status=${status}&no=${no}&name=${name}"> [ ${i } ] </a>
                </c:if>
            </c:if>
            <c:if test="${pageClass.currentPage == i }">
                <font color="#bbbbbb">[ ${i } ]</font>
            </c:if>
        </c:forEach>

        <c:if test="${pageClass.numPageGroup < pageClass.pageGroupCount }">
            <c:if test="${pageClass.pageName == 'gamesList' }">
                <a href="./${pageClass.pageName }.ga?pageNum=${pageClass.numPageGroup * pageClass.pageGroupSize + 1 }">[다음]</a>
            </c:if>
            <c:if test="${pageClass.pageName == 'searchGames' }">
                <a href="./${pageClass.pageName }.ga?pageNum=${pageClass.numPageGroup * pageClass.pageGroupSize + 1 }&datepick1=${datepick1}&datepick2=${datepick2}&status=${status}&no=${no}&name=${name}">[다음]</a>
            </c:if>
        </c:if>
    </c:if>
    </div>
    
</body>

</html>